
/**
 * @fileoverview slider serves as the main component of HTML Image Slider.
 * @author honza.rychtar@gmail.com (Jan Rychtar)
 */


goog.provide('georeferencer.slider');


goog.require('georeferencer.slider.Dragger');
goog.require('georeferencer.slider.Handler');
goog.require('goog.net.XhrIo');


/**
 * The function handles a jsonp call.
 * @param {String} data JsonP callback data.
 */
georeferencer.slider.getData = function(data) {
  georeferencer.slider.handler.newBatch(data);
};


/**
 * The main function that creates and initiates the Slider table
 * and insert it into the div with id 'slider' .
 * the slider table is to be inserted.
 */
georeferencer.slider.main = function() {    
  var sliderDivID = "slider";
  var sql = georeferencer.slider.main.getUrlParameter("sql");
  var iframeHeight = goog.dom.getViewportSize().height;
  var iframeWidth = goog.dom.getViewportSize().width;
  var numberOfRows = Math.floor(iframeHeight / 100);
  var thumbsForCanvas = Math.ceil(iframeWidth / 116) * numberOfRows;
  var limit = thumbsForCanvas * 2;
  if (limit < 30) {
    limit = 30;
  }  
  georeferencer.slider.handler = new georeferencer.slider.Handler(
    sql, sliderDivID, iframeHeight, limit, numberOfRows);
  georeferencer.slider.dragger = new georeferencer.slider.Dragger(
    georeferencer.slider.handler, 1300);
  georeferencer.slider.handler.getMoreImages();
};


georeferencer.slider.main.getUrlParameter = function(key) {
  var query = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for(var i = 0; i < query.length; i++) {
    keyValue = query[i].split('=');	  
    if(keyValue[0] == key) {
      return query[i].substring(keyValue[0].length + 1, query[i].length);
    }
  }
  return "";
};



/**
 * @return {boolean} True if links are clickable, false othewise.
 */
georeferencer.slider.isLinkEnabled = function() {
  return !georeferencer.slider.dragger.isDragging();
};


goog.exportSymbol('main', georeferencer.slider.main);
goog.exportSymbol('georeferencer.slider.isLinkEnabled',
  georeferencer.slider.isLinkEnabled);
goog.exportSymbol('getData', georeferencer.slider.getData);
